//
//  ExampleCell.swift
//  KaMengApplication
//
//  Created by DUONIU_MAC on 2018/11/2.
//  Copyright © 2018年 DUONIU_MAC. All rights reserved.
//

import UIKit

class ExampleCell: UITableViewCell {
    
    fileprivate let bankImage = UIImageView() //图标
    fileprivate let bankLabel = UILabel() //银行
    fileprivate let numberLabel = UILabel() //卡号
    fileprivate let nameLabel = UILabel() //名字
    
    fileprivate let amountTipLabel = UILabel()
    fileprivate let linesTipLabel = UILabel()
    fileprivate let dateTipLabel = UILabel()
    
    fileprivate let amountLabel = UILabel() //应还金额
    fileprivate let linesLabel = UILabel() //剩余额度
    fileprivate let dateLabel = UILabel() //日期

    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        self.contentView.backgroundColor = UIColor.mineColor()
    
        
        let whiteView = UIView()
        whiteView.backgroundColor = UIColor.white
        whiteView.layer.cornerRadius = 10
        whiteView.layer.masksToBounds = true
        self.contentView.addSubview(whiteView)
        
        let exampleImage = UIImageView()
        exampleImage.image = #imageLiteral(resourceName: "silika")
        whiteView.addSubview(exampleImage)
    
        
        bankImage.image = UIImage.imageWithName("yinlian")
        whiteView.addSubview(bankImage)
        
        bankLabel.text = "中国银行信用卡"
        bankLabel.font = UIFont.systemFont(ofSize: RATIO(maxNum: 16))
        whiteView.addSubview(bankLabel)
        
        nameLabel.text = name
        nameLabel.font = UIFont.systemFont(ofSize: RATIO(maxNum: 14))
        whiteView.addSubview(nameLabel)
        
        numberLabel.text = lastNumber
        numberLabel.font = UIFont.systemFont(ofSize: RATIO(maxNum: 14))
        whiteView.addSubview(numberLabel)
        
        amountLabel.text = "¥ 0.00"
        amountLabel.font = UIFont.boldSystemFont(ofSize: RATIO(maxNum: 16))
        whiteView.addSubview(amountLabel)
        
        linesLabel.text = "¥ 0.00"
        linesLabel.font = UIFont.boldSystemFont(ofSize: RATIO(maxNum: 16))
        whiteView.addSubview(linesLabel)
        
        dateLabel.text = "2018.01.01"
        dateLabel.font = UIFont.boldSystemFont(ofSize: RATIO(maxNum: 16))
        whiteView.addSubview(dateLabel)
        
        amountTipLabel.text = payAmount
        amountTipLabel.font = UIFont.systemFont(ofSize: RATIO(maxNum: 14))
        amountTipLabel.textColor = UIColor.gray
        whiteView.addSubview(amountTipLabel)
        
        linesTipLabel.text = remainingAmount
        linesTipLabel.font = UIFont.systemFont(ofSize: RATIO(maxNum: 14))
        linesTipLabel.textColor = UIColor.gray
        whiteView.addSubview(linesTipLabel)
        
        dateTipLabel.text = expiryDate
        dateTipLabel.font = UIFont.systemFont(ofSize: RATIO(maxNum: 14))
        dateTipLabel.textColor = UIColor.gray
        whiteView.addSubview(dateTipLabel)
        
        whiteView.snp.makeConstraints { (make) in
            make.edges.equalToSuperview().inset(UIEdgeInsets.init(top: 5, left: 10, bottom: 5, right: 10))
        }
        
        exampleImage.snp.makeConstraints { (make) in
            make.top.right.equalToSuperview()
            make.width.height.equalTo(RATIO_H(maxNum: 40))
        }
        
        bankImage.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(RATIO_H(maxNum: 10))
            make.left.equalToSuperview().offset(RATIO(maxNum: 10))
            make.width.height.equalTo(RATIO_H(maxNum: 20))
        }
        
        bankLabel.snp.makeConstraints { (make) in
            make.left.equalTo(bankImage.snp.right).offset(RATIO(maxNum: 10))
            make.centerY.equalTo(bankImage)
            make.width.greaterThanOrEqualTo(10)
            make.height.greaterThanOrEqualTo(10)
        }
    
        nameLabel.snp.makeConstraints { (make) in
            make.left.equalTo(bankLabel.snp.right).offset(RATIO(maxNum: 10))
            make.centerY.equalTo(bankLabel)
            make.width.lessThanOrEqualTo(RATIO(maxNum: 40))
            make.height.greaterThanOrEqualTo(10)
        }
        
        numberLabel.snp.makeConstraints { (make) in
            make.left.equalTo(nameLabel.snp.right).offset(RATIO(maxNum: 10))
            make.centerY.equalTo(nameLabel)
            make.width.greaterThanOrEqualTo(10)
            make.height.greaterThanOrEqualTo(10)
        }
        
        linesLabel.snp.makeConstraints { (make) in
            make.centerX.equalToSuperview()
            make.width.greaterThanOrEqualTo(10)
            make.height.equalTo(RATIO_H(maxNum: 20))
            make.top.equalTo(numberLabel.snp.bottom).offset(RATIO_H(maxNum: 15))
        }
        
        amountLabel.snp.makeConstraints { (make) in
            make.left.equalToSuperview().offset(RATIO(maxNum: 20))
            make.centerY.equalTo(linesLabel)
            make.width.greaterThanOrEqualTo(10)
            make.height.equalTo(linesLabel)
        }
        
        dateLabel.snp.makeConstraints { (make) in
            make.right.equalToSuperview().offset(RATIO(maxNum: -20))
            make.centerY.equalTo(amountLabel)
            make.width.greaterThanOrEqualTo(10)
            make.height.equalTo(amountLabel)
        }
        
        linesTipLabel.snp.makeConstraints { (make) in
            make.centerX.equalToSuperview()
            make.top.equalTo(linesLabel.snp.bottom).offset(RATIO_H(maxNum: 5))
            make.width.greaterThanOrEqualTo(10)
            make.height.equalTo(linesLabel)
        }
        
        amountTipLabel.snp.makeConstraints { (make) in
            make.left.equalTo(amountLabel)
            make.centerY.equalTo(linesTipLabel)
            make.width.greaterThanOrEqualTo(10)
            make.height.equalTo(linesTipLabel)
        }
        
        dateTipLabel.snp.makeConstraints { (make) in
            make.right.equalTo(dateLabel)
            make.centerY.equalTo(amountTipLabel)
            make.width.greaterThanOrEqualTo(10)
            make.height.equalTo(amountTipLabel)
        }
        
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

}
